//

// (  )
//

package com.dianxinos.acceleratecore.logic.clean.impl;

import android.content.Context;
import android.text.TextUtils;

import com.dianxinos.acceleratecore.logic.clean.intf.ICleanDirFileInfo;
import com.dianxinos.acceleratecore.logic.clean.intf.ICleanEnumDirFile;
import com.tools.acceleratecore.AccelerateCoreFactory;
import com.tools.acceleratecore.logic.clean.intf.ICleanMgr;
import com.tools.acceleratecore.logic.clean.intf.ICleanMgrListener;
import com.tools.acceleratecore.xlib.XLibFactory;
import com.tools.acceleratecore.xlib.xlib.impl.XObserver;
import com.tools.acceleratecore.xlib.xlib.intf.IXThreadTask;
import com.tools.acceleratecore.xlib.xlib.intf.IXThreadTaskListener;

import java.util.Iterator;

public class CleanMgr extends XObserver<ICleanMgrListener> implements ICleanMgr {
    private Context mContext = null;
    private boolean mInited = false;
    private IXThreadTask mIXThreadTaskInit = null;

    public native CleanDirFileInfo nativeScanDirFileInfo(String var1, int var2);

    public native CleanEnumDirFile nativeScanDirEnumDirFile(String var1, int var2);

    public native boolean nativeDeleteDir(String var1, String var2);

    public CleanMgr() {
        this.mContext = AccelerateCoreFactory.getApplication();
        this._init();
    }

    private void _init() {
        this.mIXThreadTaskInit = (IXThreadTask)XLibFactory.getInstance().createInstance(IXThreadTask.class);
    }

    public boolean init() {
        if(this.mInited) {
            return false;
        } else {
            this.mInited = true;
            this.mIXThreadTaskInit.start(new IXThreadTaskListener() {
                public void onThreadWork() {
                }

                public void onThreadComplete() {
                    synchronized(CleanMgr.this.mListListener) {
                        Iterator var3 = CleanMgr.this.getListListener().iterator();

                        while(var3.hasNext()) {
                            ICleanMgrListener listener = (ICleanMgrListener)var3.next();
                            listener.onCleanMgrInitComplete();
                        }

                    }
                }
            });
            return true;
        }
    }

    public ICleanDirFileInfo startScanDirFileInfoSyn(String strDirPath, int nDepth) {
        return this.scanDirFileInfo(strDirPath, nDepth);
    }

    private ICleanDirFileInfo scanDirFileInfo(String strDirPath, int nDepth) {
        return TextUtils.isEmpty(strDirPath)?null:this.nativeScanDirFileInfo(strDirPath, nDepth);
    }

    public ICleanEnumDirFile startScanDirEnumDirFileSyn(String strDirPath, int nEnumType) {
        return this.scanDirEnumDirFile(strDirPath, nEnumType);
    }

    private ICleanEnumDirFile scanDirEnumDirFile(String strDirPath, int nEnumType) {
        return TextUtils.isEmpty(strDirPath)?null:this.nativeScanDirEnumDirFile(strDirPath, nEnumType);
    }

    public boolean startDeleteDirSyn(String strDirPath, String strFileExtFilter) {
        return this.deleteDir(strDirPath, strFileExtFilter);
    }

    private boolean deleteDir(String strDirPath, String strFileExtFilter) {
        return TextUtils.isEmpty(strDirPath)?false:this.nativeDeleteDir(strDirPath, strFileExtFilter);
    }
}
